﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Ppt = Microsoft.Office.Interop.PowerPoint;

namespace ObjectModel.PowerPoint.RulesModel
{   
    public enum Alignment { TopLeft, Top, TopRight, Left, Centre, Right, BottomLeft, Bottom, BottomRight }
    
    /// <summary>
    /// Defines an action that aligns a shape or a copy of a shape to a PowerPoint object,
    /// e.g. another shape, a chart point, etc.
    /// </summary>
    public class AlignShapeToAction : Action
    {
        private bool mCopy = true;

        public Alignment TargetAlignment { get; set; }

        public Alignment ShapeAlignment { get; set; }

        public bool Copy
        {
            get { return mCopy; }
            set { mCopy = value; }
        }

        public ResolvableShape ShapeToAlign { get; set; }

        public ResolvableShape CurrentlyAlignedShape { get; set; }

        public int XOffset { get; set; }
        
        public int YOffset { get; set; }

        public override void Perform()
        {
            Ppt.Shape shape = ShapeToAlign.Resolve() as Ppt.Shape;
            object target = Target.Resolve();

            if (Copy)
            {
                // Remove existing shape.
                Ppt.Shape current = CurrentlyAlignedShape.Resolve() as Ppt.Shape;
                current.Delete();
                
                Ppt.Shape copy = shape.CopyTo(((Ppt.Shape)target).GetSlide());
                CurrentlyAlignedShape = new ResolvableShape(copy);
            }


            shape.AlignTo(target, new Offsets(XOffset, YOffset), ShapeAlignment, TargetAlignment);
        }
    }
}
